package com.spoto.oa.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;

import com.spoto.oa.dao.ProductDao;
import com.spoto.oa.dao.impl.ProductDaoImpl;
import com.spoto.oa.model.Employee;

public class EditProductTypeServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public EditProductTypeServlet() {
		super();
	}

	@Override
	public void service(ServletRequest req, ServletResponse res)
			throws ServletException, IOException {
		ProductDao proDao=new ProductDaoImpl();
		String op_type=req.getParameter("op_type");
		HttpServletResponse response=(HttpServletResponse)res;
		if(op_type.equals("list")){
			req.setAttribute("types", proDao.getType());
			req.getRequestDispatcher("product/edit_type.jsp").forward(req, res);
		}else if(op_type.equals("multi_del")){
			String[] delType = req.getParameterValues("del-flag");
			for (int i = 0; i < delType.length; i++) {
				System.out.println(delType[i]);
				proDao.delType(delType[i]);
			}
			response.sendRedirect("EditTypeServlet?op_type=list");
		}
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); 
	}

	/**
	 * Initialization of the servlet. <br>
	 * 
	 * @throws ServletException
	 *             if an error occurs
	 */
	public void init() throws ServletException {

	}

}
